home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 7 / FM Towns Free Software Collection 7.iso / t_os / numcro / numcro.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-30  |  7.5 KB  |  314 lines

  1. /***********************************************/
  2. /*                                             */
  3. /* <NUMCRO> Ver 1.00                           */
  4. /*  All rights reserved , Copyright (c) by RYO */
  5. /*                         19  Feb. 1992       */
  6. /*                                             */
  7. /***********************************************/
  8.  
  9. #include "NUMCRO.H"
  10.  
  11. int  number[LMAX][CMAX];
  12. char ncword[LMAX][CMAX][2];
  13. int  line,colm,l,c;
  14.  
  15. main(int argc , char *argv[])
  16. {
  17. int arg,no,fileflag,i,j;
  18. char tx,input,temp[2],path[_MAX_PATH],drive[_MAX_DRIVE],dir[_MAX_DIR],fname[_MAX_FNAME],ext[_MAX_EXT];
  19. FILE *nolist,*wdlist;
  20.  
  21.  
  22. /***** スターティングメッセージの表示 *****/
  23.     sprint("\n <NUMCRO> Ver 1.00\n  All rights reserved , Copyright (c) by RYO\n                         19 Feb. 1992\n\n");
  24. /***** コマンドラインパラメータの省略値の設定 *****/
  25.     line=LDEF;                       /* Cross Word Arrey Line   Size Set */
  26.     colm=CDEF;                       /* Cross Word Arrey Column Size Set */
  27.     fileflag=0;                                  /* No File Name Specify */
  28.  
  29. /***** コマンドラインパラメータの処理 *****/
  30.     for(arg=1 ; arg<argc ; arg++)
  31.        {
  32.        if      (*argv[arg]=='?')
  33.           {
  34. HELP:          sprint("\nUSAGE --- numcro [<ファイル名>] [-L<行数>] [-C<桁数>]");
  35.           sprint("\n               順不同。行数,桁数省略値はそれぞれ");
  36.           iprint(LDEF,2);
  37.           putchar(',');
  38.           iprint(CDEF,2);
  39.           exit(0);
  40.           }
  41.        else if (*argv[arg]=='-')
  42.           {
  43.           switch(toupper(*(argv[arg]+1)))
  44.              {
  45.              case'?':goto HELP;
  46.              case'L':no=atoi(argv[arg]+2);
  47.              if ((2<=no)&&(no<=LMAX)) line=no;
  48.                  break;
  49.              case'C':no=atoi(argv[arg]+2);
  50.              if ((2<=no)||(no<=CMAX)) colm=no;
  51.                  break;
  52.              default:sprint("\nUndefined Parameter --- ");
  53.                  sprint(argv[arg]);
  54.                  exit(1);
  55.          }
  56.           }
  57.        else
  58.           {
  59.           _splitpath(argv[arg],drive,dir,fname,ext);
  60.           fileflag=1;
  61.           }
  62.        }
  63.  
  64. /***** 対象問題表示/入力領域の初期化 *****/
  65.     for(i=0 ; i<LMAX ; i++)
  66.        {
  67.        for(j=0 ; j<CMAX ; j++)
  68.           {
  69.           number[i][j]=0;
  70.           strncpy(ncword[i][j],"■",2);
  71.                 }
  72.        }
  73.     if (fileflag)                                   /* File Name Specify */
  74.        {
  75.        _makepath(path,drive,dir,fname,".NCN");
  76.        if (access(path,6)==0)                             /* File Exists */
  77.           {
  78.           nolist=fopen(path,"rb");
  79.           _makepath(path,drive,dir,fname,".NCW");
  80.           wdlist=fopen(path,"rb");
  81.           line=getc(nolist);
  82.           colm=getc(nolist);
  83.           for(i=0 ; i<line ; i++)
  84.              {
  85.              for(j=0 ; j<colm ; j++)
  86.             {
  87.             number[i][j]=getc(nolist);
  88.             ncword[i][j][0]=getc(wdlist);
  89.             ncword[i][j][1]=getc(wdlist);
  90.             }
  91.          }
  92.           fclose(nolist);
  93.           fclose(wdlist);
  94.           }
  95.        else fileflag=-1;                          /* Nothing , Nwe Files */
  96.        }
  97.     l=c=0;
  98.     putchar('\f');
  99.  
  100.     if (fileflag==1) goto WORD;
  101. /***** 問題入力画面の処理 *****/
  102. NUMBER:    printf("\x1B= 8☆☆☆  問題入力画面  ☆☆☆");
  103.     for(i=0 ; i<line ; i++)
  104.        {
  105.        for(j=0 ; j<colm ; j++)
  106.           {
  107.           locate(i,j);
  108.           if (number[i][j]) iprint(number[i][j],2);
  109.           else              sprint("■");
  110.           }
  111.        }
  112.     no='\0';
  113.     while(1)
  114.        {
  115.        locate(l,c);
  116.        if (number[l][c])
  117.           {
  118.           revers();
  119.           iprint(number[l][c],2);
  120.           normal();
  121.           }
  122.        else sprint("■");
  123.        locate(l,c);
  124.        input=getch();
  125.        locate(l,c);
  126.        if (number[l][c]) iprint(number[l][c],2);
  127.        if      (input=='\x1B') goto EXIT;
  128.        else if (input=='\b') break;
  129.        else if (input==RIGHT)
  130.           {
  131.           nextcolm();
  132.           no='\0';
  133.           }
  134.        else if (input==LEFT)
  135.           {
  136.           revscolm();
  137.           no='\0';
  138.           }
  139.        else if (input==DOWN)
  140.           {
  141.           nextline();
  142.           no='\0';
  143.           }
  144.        else if (input==UP)
  145.           {
  146.           revsline();
  147.           no='\0';
  148.           }
  149.        else if (('0'<=input)&&(input<='9'))
  150.           {
  151.           if (no=='\0')
  152.          {
  153.          no=input;
  154.          number[l][c]=no-'0';
  155.          if (number[l][c]) strncpy(ncword[l][c],"□",2);
  156.          else              strncpy(ncword[l][c],"■",2);
  157.          }
  158.           else
  159.          {
  160.          number[l][c]=number[l][c]*10+input-'0';
  161.          if (number[l][c]) strncpy(ncword[l][c],"□",2);
  162.          else              strncpy(ncword[l][c],"■",2);
  163.          locate(l,c);
  164.          normal();
  165.          iprint(number[l][c],2);
  166.          nextcolm();
  167.          no='\0';
  168.          }
  169.           }
  170.        }
  171. /***** 解答入力画面の処理 *****/
  172. WORD:    printf("\x1B= 8★★★  解答入力画面  ★★★");
  173.     for(i=0 ; i<line ; i++)
  174.        {
  175.        for(j=0 ; j<colm ; j++)
  176.           {
  177.           locate(i,j);
  178.           if (number[i][j])
  179.          {
  180.          putchar(ncword[i][j][0]);
  181.          putchar(ncword[i][j][1]);
  182.          }
  183.           else sprint("■");
  184.           }
  185.        }
  186.     while(1)
  187.        {
  188.        locate(l,c);
  189.        revers();
  190.        if (number[l][c])
  191.           {
  192.           putchar(ncword[l][c][0]);
  193.           putchar(ncword[l][c][1]);
  194.           }
  195.        else sprint("■");
  196.        normal();
  197.        locate(l,c);
  198.        input=getch();
  199.        locate(l,c);
  200.        if (number[l][c])
  201.           {
  202.           putchar(ncword[l][c][0]);
  203.           putchar(ncword[l][c][1]);
  204.           }
  205.        else sprint("■");
  206.        if      (input=='\x1B') break;
  207.        else if (input=='\b') goto NUMBER;
  208.        else if (input==RIGHT) nextcolm();
  209.        else if (input==LEFT)  revscolm();
  210.        else if (input==DOWN)  nextline();
  211.        else if (input==UP)    revsline();
  212.        else if (input=='\t')
  213.           {
  214.           if (number[l][c])
  215.          {
  216.          temp[0]=ncword[l][c][0];
  217.          temp[1]=ncword[l][c][1];
  218.          sprint("\x1B[5;36m");
  219.          repaint(number[l][c],"□");
  220.          normal();
  221.          locate(l,c);
  222.          while(getch()!='\t');
  223.          repaint(number[l][c],temp);
  224.          }
  225.           }
  226.        else if (input==' ')
  227.           {
  228.           if (number[l][c]) repaint(number[l][c],"□");
  229.           nextcolm();
  230.           }
  231.        else if ((('!'<=input)&&(input<='~'))||
  232.             (('\xA1'<=input)&&(input<='\xDF'))  )
  233.           {
  234.           if (number[l][c])
  235.          {
  236.          ncword[l][c][0]=input;
  237.          ncword[l][c][1]=' ';
  238.          repaint(number[l][c],ncword[l][c]);
  239.          }
  240.           nextcolm();
  241.           }
  242.        else if ((('\x81'<=input)&&(input<='\x9F'))||
  243.             (('\xE0'<=input)&&(input<='\xFC'))  )
  244.           {
  245.           if (number[l][c])
  246.          {
  247.          ncword[l][c][0]=input;
  248.          ncword[l][c][1]=getch();
  249.          repaint(number[l][c],ncword[l][c]);
  250.          }
  251.           else getch();
  252.           nextcolm();
  253.           }
  254.        }
  255. /***** 終了処理 *****/
  256. EXIT:    putchar('\f');
  257.     if (fileflag)
  258.        {
  259.        if (fileflag==1)
  260.           {
  261.           sprint("既存のファイルを書き換えてもいいですか?(Y/N)=");
  262.           if (answer()) sprint("Yes");
  263.           else
  264.          {
  265.          sprint("No");
  266.          goto PRINT;
  267.          }
  268.           }
  269.        _makepath(path,drive,dir,fname,".NCN");
  270.        nolist=fopen(path,"wb");
  271.        _makepath(path,drive,dir,fname,".NCW");
  272.        wdlist=fopen(path,"wb");
  273.        putc(line,nolist);
  274.        putc(colm,nolist);
  275.        for(l=0 ; l<line ; l++)
  276.           {
  277.           for(c=0 ; c<colm ; c++)
  278.          {
  279.          putc(number[l][c]   ,nolist);
  280.          putc(ncword[l][c][0],wdlist);
  281.          putc(ncword[l][c][1],wdlist);
  282.          }
  283.           }
  284.        fclose(nolist);
  285.        fclose(wdlist);
  286.        }
  287. PRINT:    sprint("\n数字/文字対応表\を出力しますか?(Y/N)=");
  288.     if (answer())
  289.        {
  290.        sprint("Yes\n");
  291.        for(no=1 ; (no<line*colm)&&(no<=99) ; no++)
  292.           {
  293.           for(i=0 ; i<line ; i++)
  294.          {
  295.          for(j=0 ; j<colm ; j++)
  296.             {
  297.             if (no==number[i][j])
  298.                {
  299.                iprint(no,2);
  300.                putchar('=');
  301.                putchar(ncword[i][j][0]);
  302.                putchar(ncword[i][j][1]);
  303.                sprint(" , ");
  304.                break;
  305.                }
  306.             }
  307.          if (j<colm) break;
  308.          }
  309.           }
  310.        }
  311.     else sprint("No");
  312.     exit(0);
  313. }
  314.